/**
 * 
 */
package com.googlecode.xcarve.transport;

import java.net.InetSocketAddress;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.googlecode.xcarve.common.config.ServerConfig;
import com.googlecode.xcarve.exception.CarveException;



/**
 * @author duxinyun
 *
 */
public abstract class AbstractServer implements Server{

	static final Logger logger = LoggerFactory.getLogger(AbstractServer.class);
	
	public volatile ServerConfig 		   serviceConfig;
	public InetSocketAddress              bindAddress; 
	
	public AbstractServer(ServerConfig serviceConfig) throws CarveException{
		try {
			this.serviceConfig = serviceConfig;
			bindAddress = new InetSocketAddress(serviceConfig.getHost(), serviceConfig.getRemotePort());
			doBind();
		} catch (Throwable e) {
			throw new RuntimeException(e);
		}
	}
	
	protected abstract void doBind()throws Throwable;
	
}
